﻿using Demo.PetaPoco.Application.Services.User;
using Microsoft.Extensions.Logging;
using PmSoft.Core.Job;

namespace Demo.PetaPoco.Application.Jobs;

/// <summary>
/// 示例作业，展示如何注入 Scope 服务和日志
/// </summary>
[JobSchedule("SampleJob", "0/10 * * * * ?")] // 每10秒执行（Quartz），Timer 可改为 "10"
//[JobSchedule("SampleJob", "10")]
public class SampleJob : IJobDefinition
{
	private readonly UserService _userService;
	private readonly ILogger<SampleJob> _logger;

	/// <summary>
	/// 构造函数，注入 Scope 服务和日志记录器
	/// </summary>
	/// <param name="scopedService">示例 Scope 服务</param>
	/// <param name="logger">日志记录器</param>
	public SampleJob(UserService userService, ILogger<SampleJob> logger)
	{
		_userService = userService;
		_logger = logger;
	}

	/// <summary>
	/// 执行作业逻辑
	/// </summary>
	public async Task Execute()
	{
		_logger.LogInformation("SampleJob 开始执行");
		await _userService.GetUserAsync(100);
		_logger.LogInformation("SampleJob 执行完成");
	}
}
